package cn.hrlly.tao2shou.view.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.Button;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.hrlly.tao2shou.R;
import cn.hrlly.tao2shou.view.base.BaseFragment;
import cn.hrlly.tao2shou.view.fragment.BuyerCompleteOrderFragment;
import cn.hrlly.tao2shou.view.fragment.BuyerUnfinishOrderFragment;

public class BuyerOrderActivity extends BaseFragment{

    @Bind(R.id.btnUnfinishOrder)
    Button btnUnfinishOrder;
    @Bind(R.id.btnCompleteOrder)
    Button btnCompleteOrder;
    @Bind(R.id.viewPager)
    ViewPager viewPager;
    private FragmentPagerAdapter adapter;
    private List<Fragment> list;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_buyer_order);
        ButterKnife.bind(this);
        init();
    }

    //初始化控件
    public void init(){
        list=new ArrayList<Fragment>();
        BuyerUnfinishOrderFragment buyerUnfinishOrderFragment=new BuyerUnfinishOrderFragment();
        BuyerCompleteOrderFragment buyerCompleteOrderFragment=new BuyerCompleteOrderFragment();
        list.add(buyerUnfinishOrderFragment);
        list.add(buyerCompleteOrderFragment);

        adapter=new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return list.get(position);
            }
            @Override
            public int getCount() {
                return list.size();
            }
        };
        viewPager.setAdapter(adapter);
    }

    //button的点击事件
    @OnClick({R.id.btnUnfinishOrder,R.id.btnCompleteOrder})
    public void click(View view){
        switch (view.getId()){
            case R.id.btnUnfinishOrder:
                viewPager.setCurrentItem(0);;
                break;
            case R.id.btnCompleteOrder:
                viewPager.setCurrentItem(1);
                break;
            default:
                break;
        }
    }

}
